package com.itqf;

import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.impl.matchers.GroupMatcher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2021/1/26
 * @Time: 下午2:44
 */
public class TestSpringZHQuartzGroup {
    public  static  void  main(String[]args){

        //autoStartup = true;  自动启动
        ApplicationContext ac = new ClassPathXmlApplicationContext("spring-quartz1.xml");



        try {
            //Thread.sleep(2000);

            Scheduler scheduler = ac.getBean(Scheduler.class);

            //暂停任务组  myJob   myJob1  都在 myJobGroup
            //GroupMatcher<JobKey> var1
            GroupMatcher groupMatcher = GroupMatcher.groupEquals("myJobGroup");

            scheduler.pauseJobs(groupMatcher);
            Thread.sleep(4000);
            //恢复任务
            scheduler.resumeJobs(groupMatcher);

            Thread.sleep(4000);

            List<JobKey> list = new ArrayList<>();
            list.add(JobKey.jobKey("myJob","myJobGroup"));
            list.add(JobKey.jobKey("myJob1","myJobGroup"));

            scheduler.deleteJobs(list);
            System.out.println("end");

        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
